<?php
namespace Home\Controller;
use Think\Controller;
class MemberController extends CommonController {
	protected $table = 'user';
	protected $integral = 'integral';	
	protected $address = 'address';	
	protected $order = 'order';	
	protected $order_product = 'order_goods';	
	protected $reimburse = 'reimburse';	
	protected $store = 'store';	
	protected $collect = 'collect';	
	protected $product = 'product';	
	protected $tb_pay = 'payment' ;//支付方式表

	/*
	*会员中心
	*/	
    public function index(){
    	// $User->where('score=100')->limit(3)->save(array('level'=>'A'));
    	$where['order_state']=10;
    	$this->zt=$where['order_state'];
    	$this->style='style="color: #333;"';
    	$this->style2='style="color: #FD6760;"';

    	$where['buyer_id']=$_SESSION['user_id'];
    	
		// $order='id DESC';
		$z_order = M($this->order)->where($where)->limit(2)->select();
		$count_order = M($this->order)->where($where)->count();
		if($count_order>2){
			$this->cx=1;

		}
		$where['order_state']='10';
		$this->dfk=M($this->order)->where($where)->count();
		$where['order_state']='20';
		$this->dsh=M($this->order)->where($where)->count();
		$where['order_state']='30';
		$this->dpj=M($this->order)->where($where)->count();

		$this->assign('z_order',$z_order);
		 //dump($z_order);

    	$map['userid']=$_SESSION['user_id'];
		$map['sc_lx']='sp';
    	
    	$zscid = M($this->collect)->field("sc_id")->where($map)->order('id DESC')->select();

		$ff=array();
		for($i=0;$i<count($zscid);$i++)
        {
        	$ff[]= array('like',$zscid[$i]['sc_id']);
        }
        $a=count($ff);
        if($a>=1){
        	$ff[$a]='ThinkPHP';
            $ff[$a+1]='or';

            $data['id']=$ff;
        }else{
        	$data['id']='';
        }
// dump($ff);

		$list = M($this->product)->where($data)->limit(3)->select();
		for($i=0;$i<count($list);$i++)
        {
        	$dp = M($this->store)->where(array('store_id'=>$list[$i]['st_id']))->find();
        	$list[$i]['dpname']=$dp['store_name'];//店铺名称
        	// dump($dp);
        	$list[$i]['scrq'] = 0;
        	$list[$i]['z_xs'] = 0;
        	$list[$i]['z_pl'] = 0;
        	$list[$i]['scrq'] += M($this->collect)->where(array('sc_id'=>$list[$i]['id']))->count();//总收藏人气
        	$list[$i]['z_xs'] += M($this->order_product)->where(array('product_id'=>$list[$i]['id']))->sum('product_num');//总出售数量
        	// $list[$i]['z_pl'] += M($this->comment)->where(array('product_id'=>$list[$i]['id']))->count();//总评论数
        	$map['sc_id']=$list[$i]['id'];
        	$scid = M($this->collect)->where($map)->find();
        	$list[$i]['sc_id'] = $scid['id'];//收藏记录id

        }

    	
    	$this->assign('scsp',$list);


    	$map2['userid']=$_SESSION['user_id'];
		$map2['sc_lx']='dp';
    	
    	$zscid = M($this->collect)->field("sc_id")->where($map2)->order('id DESC')->select();

		$ff=array();
		for($i=0;$i<count($zscid);$i++)
        {
        	$ff[]= array('like',$zscid[$i]['sc_id']);
        }
        $a=count($ff);
        if($a>=1){
        	$ff[$a]='ThinkPHP';
            $ff[$a+1]='or';

            $data2['store_id']=$ff;
        }else{
        	$data2['store_id']='';
        }


		$list2 = M($this->store)->where($data2)->limit(2)->select();

    	
    	$this->assign('scdp',$list2);

		$this->display();	
		 
    }
	
	/*
	*会员头像 userpic
	*/	
    public function MyPic(){
				
		$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//修改
			$hash = $this->SuijiHash('SuijiHash',I('post.pichash'));
			if ($hash) {
				$img = upload();
			} else {
				$img = false;
			}
			//S($cache,null);	
			//dump($img);die;
			if ($img){
				session('PicH',null);
				$data2['userpic'] = $img ;
				//关联查询
				$edit = _getEdit($this->table,$str,$data,$data2,$cache);
				if ($edit) {
					$this->redirect('member/xgtx','上传成功！');
				}
			} 					
		} 			
		$this->display();		 
    }


	/*
	*随机hash
	*/	
    public function SuijiHash($SuijiHash,$hash){
		
		if ($_SESSION[$SuijiHash]==$hash) {
			return false;
		} elseif (!$_SESSION[$SuijiHash]) {
			session($SuijiHash,$hash);
			return true;
		} else {
			session($SuijiHash,$hash);
			return true;			
		}
    }	

	/*
	* 账户信息 /修改信息/基本信息
	*/	
	public function info_cset() {		
		$this->display();
	}
	
	/*
	* 账户信息 /修改信息/基本信息
	*/	
	public function info_get() {
		$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('InfoHash',I('post.Infohash'));	
			
			if ($hash){
				I('post.member_truename') && $data2['realname'] = I('post.member_truename') ;//真实姓名
				I('post.member_sex') && $data2['sex'] = I('post.member_sex') ;//性别
				I('post.province') && $data2['province'] = I('post.province') ;//省
				I('post.city') && $data2['city'] = I('post.city') ;//市
				I('post.area') && $data2['area'] = I('post.area') ;//区
				
				if ($data2) {
					//修改
					$edit = _getEdit($this->table,$str,$data,$data2,$cache);

				}

				if ($edit) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('修改成功！');self.location=document.referrer;</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
			}
			
		} else {
			echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
		} 			
	}
	
	/*
	*会员中心左边导航 userpic
	*/	
    public function menuleft(){
		
		if ($_SESSION['user_id']) {
	
			$this->display();		
		} else {			
			$this->redirect('/login','请先登录！');
		}
		 
    }

    /*
	*账户余额
	*/	
    public function integral(){
		
	    $this->display(); 
    }

    /*
	*账户安全
	*/	
    public function account_aq(){
		
	    $this->display(); 
    }

    /*
	*修改登录密码
	*/	
    public function xg_dlpassword(){

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('passwordhash',I('post.passwordhash'));	
			
			if ($hash){

				$ymm = I('post.member_password');
                $xmm = I('post.member_newpassword');
                $qrxmm = I('post.member_qrnewpassword');
                if(!$ymm){
                	echo "<SCRIPT language=JavaScript>alert('请输入旧登录密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!$xmm){
                	echo "<SCRIPT language=JavaScript>alert('请输入新登录密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!$qrxmm){
                	echo "<SCRIPT language=JavaScript>alert('请输入确认新登录密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                $Userinfo = _goLogin($this->table,$str,$data);
                // if(md5($ymm)!=$Userinfo['password']){
                // 	echo "<SCRIPT language=JavaScript>alert('旧登录密码输入错误！');javascript:history.go(-1);</SCRIPT>";
                // 	die();
                // }
                if(!_checkPwd(MD5($ymm),$Userinfo['password']))
                {
                    echo "<SCRIPT language=JavaScript>alert('旧登录密码输入错误！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                if($xmm!=$qrxmm){
                	echo "<SCRIPT language=JavaScript>alert('新登录密码和确认新登录密码不一致！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                $data2['password'] = _enPasswd(md5($xmm));//新登录密码
				
				if ($data2) {
					//修改
					$edit = _getEdit($this->table,$str,$data,$data2,$cache);

				}

				if ($edit) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('修改成功！');location.href='/member/zhaq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }

    /*
	*验证邮箱（绑定邮箱）
	*/	
    public function yz_email(){
		
	    $this->display(); 
    }

    /*
	*绑定手机
	*/	
    public function bd_mobile(){
		
	    $this->display(); 
    }

    /*
	*设置支付密码
	*/	
    public function sz_paypassword(){

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('paypasswordhash',I('post.paypasswordhash'));	
			
			if ($hash){

                $zfmm = I('post.member_paypassword');
                $qrzfmm = I('post.member_qrpaypassword');
                if(!$zfmm){
                	echo "<SCRIPT language=JavaScript>alert('请输入支付密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!$qrzfmm){
                	echo "<SCRIPT language=JavaScript>alert('请再次输入支付密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
          
                if($zfmm!=$qrzfmm){
                	echo "<SCRIPT language=JavaScript>alert('支付密码和确认支付密码不一致！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                $data2['paypassword'] = _enPasswd(md5($zfmm));//支付密码
				
				if ($data2) {
					//修改
					$edit = _getEdit($this->table,$str,$data,$data2,$cache);

				}

				if ($edit) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('设置成功！');location.href='/member/zhaq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('设置失败！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('设置失败！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }

    /*
	*修改支付密码
	*/	
    public function xg_paypassword(){

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('xgpaypasswordhash',I('post.xgpaypasswordhash'));	
			
			if ($hash){

				$ymm = I('post.member_paypassword');
                $xmm = I('post.member_newpaypassword');
                $qrxmm = I('post.member_qrnewpaypassword');
                if(!$ymm){
                	echo "<SCRIPT language=JavaScript>alert('请输入旧支付密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!$xmm){
                	echo "<SCRIPT language=JavaScript>alert('请输入新支付密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!$qrxmm){
                	echo "<SCRIPT language=JavaScript>alert('请输入确认新支付密码！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                $Userinfo = _goLogin($this->table,$str,$data);
                // if(md5($ymm)!=$Userinfo['paypassword']){
                // 	echo "<SCRIPT language=JavaScript>alert('旧支付密码输入错误！');javascript:history.go(-1);</SCRIPT>";
                // 	die();
                // }
                if(!_checkPwd(MD5($ymm),$Userinfo['paypassword']))
                {
                    echo "<SCRIPT language=JavaScript>alert('旧支付密码输入错误！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }


                if($xmm!=$qrxmm){
                	echo "<SCRIPT language=JavaScript>alert('新支付密码和确认新支付密码不一致！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                $data2['paypassword'] = _enPasswd(md5($xmm));//新支付密码
				
				if ($data2) {
					//修改
					$edit = _getEdit($this->table,$str,$data,$data2,$cache);

				}

				if ($edit) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('修改成功！');location.href='/member/zhaq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('您没有任何改动！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }

    /*
	*收货地址
	*/	
    public function sh_address(){

    	$list = M($this->address)->where(array('userid'=>$_SESSION['user_id']))->select();

		$this->assign('list',$list);
	    $this->display(); 
    }
	
    /*
	*新增地址
	*/	
    public function add_address(){
		unset($url);
    	//$url = $_SERVER['HTTP_REFERER'];
		//dump(I('post.'));die;	
		if (IS_POST) {
			
/* 			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	 */
			//hash
			$hash = $this->SuijiHash('addresshash',I('post.addresshash'));	
			
			if ($hash){
				if(!I('post.true_name')){
					die("<SCRIPT language=JavaScript>alert('收货人不能为空！');javascript:history.go(-1);</SCRIPT>");
				} 
				
				if(!I('post.province')){
					die("<SCRIPT language=JavaScript>alert('所在地区不能为空！');javascript:history.go(-1);</SCRIPT>");
				} 

				if(!I('post.address')){
					die("<SCRIPT language=JavaScript>alert('街道地址不能为空！');javascript:history.go(-1);</SCRIPT>");
				} 

/* 				if(!I('post.tel_phone')){
					echo "<SCRIPT language=JavaScript>alert('电话号码不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				}  */
				if (I('post.tel_phone')) {
                    //正则表达式匹配
                    if (!preg_match ( ' /^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$/',I('post.tel_phone') )) {
					    die("<SCRIPT language=JavaScript>alert('电话号码格式错误，请重新输入！');javascript:history.go(-1);</SCRIPT>");
                    }
                }

				if(!I('post.mob_phone')){
					die("<SCRIPT language=JavaScript>alert('手机号码不能为空！');javascript:history.go(-1);</SCRIPT>");
				} 
				if (I('post.mob_phone')) {
                    //正则表达式匹配
                    if (!preg_match ( ' /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))\\d{8})$/',I('post.mob_phone') )) {
					    die("<SCRIPT language=JavaScript>alert('手机号码格式错误，请重新输入！');javascript:history.go(-1);</SCRIPT>");
                    }
                }

				I('post.true_name') && $data2['realname'] = I('post.true_name') ;//收货人真实姓名
				I('post.province') && $data2['province'] = I('post.province') ;//省
				I('post.city') && $data2['city'] = I('post.city') ;//市
				I('post.area') && $data2['area'] = I('post.area') ;//区
				I('post.address') && $data2['address'] = I('post.address') ;//街道地址
				I('post.tel_phone') && $data2['tel_phone'] = I('post.tel_phone') ;//电话号码
				I('post.mob_phone') && $data2['mob_phone'] = I('post.mob_phone') ;//手机号码
				I('post.is_default') && $data2['is_default'] = I('post.is_default') ;//设为默认地址 1为默认
				$data2['userid'] = $_SESSION['user_id'] ;//会员id
				
				if ($data2) {

					if($data2['is_default']==1){
						$data3['userid'] = $_SESSION['user_id'] ;
						$data3['is_default'] = 1;
					    $data4['is_default'] = 0;
					    //修改
					    $edit = _getEdit($this->address,$data3,0,$data4,$cache);
					}
       
					//添加
					$add = _getAdd($this->address,$data2,$cache);

				}
					
				if ($add) {
					unset($data2);
					if (I('post.buy_atc')) {
						return 1 ;
					} else {
						die("<script>alert('新增成功！');location.href=document.referrer;</script>") ;
					}
					
					//echo 1;
				} else {
					die( "<SCRIPT language=JavaScript>alert('新增失败！');javascript:history.go(-1);</SCRIPT>");
				}
			} else {
				die("<SCRIPT language=JavaScript>alert('新增失败！');javascript:history.go(-1);</SCRIPT>") ;
			}
			
		} else {
			die("<SCRIPT language=JavaScript>alert('新增失败！');javascript:history.go(-1);</SCRIPT>") ;
		} 			 
    }

    /*
	*编辑地址
	*/	
    public function xg_address(){

    	$cache = 'user_'.$_SESSION['user_id'];	

    	// $id=I('get.id');
    	// $list = M($this->address)->where(array('id'=>$id))->find();
    	$where['id']=I('get.id');
    	$list = _goLogin($this->address,$where,0);

		$this->assign('list',$list);

    		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('xgaddresshash',I('post.xgaddresshash'));	
			
			if ($hash){
				if(!I('post.true_name')){
					echo "<SCRIPT language=JavaScript>alert('收货人不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				} 
				
				if(!I('post.province')){
					echo "<SCRIPT language=JavaScript>alert('所在地区不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				} 

				if(!I('post.address')){
					echo "<SCRIPT language=JavaScript>alert('街道地址不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				} 

				if(!I('post.tel_phone')){
					echo "<SCRIPT language=JavaScript>alert('电话号码不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				} 
				if (I('post.tel_phone')) {
                    //正则表达式匹配
                    if (!preg_match ( ' /^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$/',I('post.tel_phone') )) {
                        echo "<SCRIPT language=JavaScript>alert('电话号码格式错误，请重新输入！');javascript:history.go(-1);</SCRIPT>";
					    die();
                    }
                }

				if(!I('post.mob_phone')){
					echo "<SCRIPT language=JavaScript>alert('手机号码不能为空！');javascript:history.go(-1);</SCRIPT>";
					die();
				} 
				if (I('post.mob_phone')) {
                    //正则表达式匹配
                    if (!preg_match ( ' /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))\\d{8})$/',I('post.mob_phone') )) {
                        echo "<SCRIPT language=JavaScript>alert('手机号码格式错误，请重新输入！');javascript:history.go(-1);</SCRIPT>";
					    die();
                    }
                }

				I('post.true_name') && $data2['realname'] = I('post.true_name') ;//收货人真实姓名
				I('post.province') && $data2['province'] = I('post.province') ;//省
				I('post.city') && $data2['city'] = I('post.city') ;//市
				I('post.area') && $data2['area'] = I('post.area') ;//区
				I('post.address') && $data2['address'] = I('post.address') ;//街道地址
				I('post.tel_phone') && $data2['tel_phone'] = I('post.tel_phone') ;//电话号码
				I('post.mob_phone') && $data2['mob_phone'] = I('post.mob_phone') ;//手机号码
				I('post.is_default') && $data2['is_default'] = I('post.is_default') ;//设为默认地址 1为默认
				$map['id'] = I('post.id') ;//id
				$map['userid'] = $_SESSION['user_id'] ;//会员id
				// dump($map);die;
				if ($data2) {

					if($data2['is_default']==1 && $data2['is_default']!=$list['is_default']){
						$data3['userid'] = $_SESSION['user_id'] ;
						$data3['is_default'] = 1;
					    $data4['is_default'] = 0;
					    //修改
					    $edit = _getEdit($this->address,$data3,0,$data4,$cache);
					}
       
					//修改
					$edit2 = _getEdit($this->address,$map,0,$data2,$cache);

				}

				if ($edit2) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('编辑成功！');self.location=document.referrer;</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('编辑失败！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('编辑失败！');javascript:history.go(-1);</SCRIPT>";
			}
			
		} 			 

		$this->display();
    }


    /*
	*删除收货地址
	*/	
    public function del_address(){
    	$cache = 'user_'.$_SESSION['user_id'];	

    	$where['id']=I('get.id');
    	$del = _getDel($this->address,$where,$data='',$cache);

    	if ($del) {
								
			echo "<SCRIPT language=JavaScript>alert('删除成功！');self.location=document.referrer;</SCRIPT>";
		} else {
			echo "<SCRIPT language=JavaScript>alert('删除失败！');javascript:history.go(-1);</SCRIPT>";
		}

 
    }

    /*
	* 实物交易订单
	*/	
	public function sw_order() {	

		if(I('get.status')){
            $status = I('get.status');
            if($status=='mr'){
            	$this->zt_mr = "selected";
            }elseif($status=='-1'){
            	$this->zt_0 = "selected";
            }elseif($status=='1'){
            	$this->zt_1 = "selected";
            }elseif($status=='2'){
            	$this->zt_2 = "selected";
            }elseif($status=='3'){
            	$this->zt_3 = "selected";
            }elseif($status=='4'){
            	$this->zt_4 = "selected";
            }elseif($status=='5'){
            	$this->zt_5 = "selected";
            }elseif($status=='6'){
            	$this->zt_6 = "selected";
            }

            if($status!='mr'){
            	$map['status']=$status;
            } 
        }

        $kstime = I('get.query_start_date');
        $jstime = I('get.query_end_date');
        $timeks=strtotime($kstime);
        $timejs=strtotime($jstime);
        if($kstime<>''){
            $this->kstime=I('get.query_start_date');
        }
        if($jstime<>''){
            $this->jstime=I('get.query_end_date');
        }
        if ($kstime <> '' && $jstime <> '') {
            $where['add_time'] = array(array('egt',$timeks),array('lt',$timejs));
        }elseif ($kstime <> '' && $jstime == '') {
            $where['add_time'] = array('egt',$timeks);
        }elseif ($kstime == '' && $jstime <> '') {
            $where['add_time'] = array('lt',$timejs);
        }

        if(I('get.order_sn')){
        	$this->order_sn = I('get.order_sn');
        	$where['order_sn']=I('get.order_sn');
        }
		
		// $cache = 'user_'.$_SESSION['user_id'];
		$where['buyer_id']=$_SESSION['user_id'];
		
		$z_order = M($this->order)->field("order_sn,order_id")->where($where)->select();
		
		//dump($z_order);die;
		$ff=array();
		for($i=0;$i<count($z_order);$i++)
        {
        	$map['order_id']=$z_order[$i]['order_id'];
        	$sptable=M($this->order_product)->where($map)->select();
        	if($sptable){
        		$ff[]= array('like',$z_order[$i]['order_sn']);

        	}

        }
        $a=count($ff);
        if($a>=1){
        	$ff[$a]='ThinkPHP';
            $ff[$a+1]='or';

            $data['order_sn']=$ff;
        }else{
        	$data['order_sn']='';
        }

		$num=6;
		$count = M($this->order)->where($data)->count();// 查询满足要求的总记录数
		$p = getpage($count, $num);

		$list = M($this->order)->where($data)->order('order_id DESC')->limit($p->firstRow, $p->listRows)->select();
		
		for($i=0;$i<count($list);$i++)
        {
        	$map['order_id']=$list[$i]['order_id'];
        	$list[$i]['sptable']=M($this->order_product)->where($map)->select();

        	$zt=M($this->order_product)->field("goods_pay_price")->where(array('order_id'=>$list[$i]['order_id']))->select();
 			//支付方式
			$pay_code = _getOne($this->tb_pay, 'payment_code="%s"', array($list[$i]['payment_code'])) ;
			
			$list[$i]['pay_name'] = $pay_code['payment_name'] ; 
			$list[$i]['shipping_fee'] = number_format($list[$i]['shipping_fee'],2) ;
					
        	foreach($zt as $k => $v){
				$v['goods_pay_price'] = number_format($v['goods_pay_price'],2) ;
        	}   	
        }
		//dump($list);die;		
		$this->assign('list',$list);
		$this->assign('page',$p->show());
		$this->display();
	}


	/*
	*确认收货
	*/	
    public function qrshh(){

    	$data=M($this->order)->where('order_id=%d',I('get.order_id'))->find();
		//dump(I('get.order_id'));die;
    	//$arr['finnshed_time']=time();//收货时间
		$arr['order_state']=40;//已收货
		
    	$reg=M($this->order)->where('order_id=%d',I('get.order_id'))->save($arr);

        if ($reg) {							
			echo "<SCRIPT language=JavaScript>alert('确认成功！');location.href='/member/swjydd.html'</SCRIPT>";
		} else {
			echo "<SCRIPT language=JavaScript>alert('确认失败！');javascript:history.go(-1);</SCRIPT>";
		}

    }

    /*
	*订单详情
	*/	
    public function order_xq(){

    	$map['order_id']=I('get.id');
    	$this->tkid=$map['order_id'];
    	if(I('get.qb')){
    		$qb='qb';
    		$this->qb=$qb;
    		$list2=M($this->order)->where($map)->find();
			
    		$map2['order_id']=$list2['order_id'];
    		$list=M($this->order_product)->where($map2)->select();

    	}else{
    		$list=M($this->order_product)->where($map)->find();
    	    $map2['order_id']=$list['order_id'];
    	    $list2=M($this->order)->where($map2)->find();

    	} 
 		//支付方式
		$pay_code = _getOne($this->tb_pay, 'payment_code="%s"', array($list2['payment_code'])) ;
			
		$list2['pay_name'] = $pay_code['payment_name'] ; 
		//dump($list2);die;
    	$this->assign('list',$list);
    	$this->assign('list2',$list2);

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('tkhash',I('post.tkhash'));	
			
			if ($hash){

                if(!I('post.tkyy')){
                	echo "<SCRIPT language=JavaScript>alert('请输入退款原因！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!I('post.face180')){
                	echo "<SCRIPT language=JavaScript>alert('请上传凭证！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                I('post.order_num') && $data2['order_sn'] = I('post.order_num') ;//订单号
                I('post.store_name') && $data2['store_name'] = I('post.store_name') ;//商铺名称
                I('post.product_pic') && $data2['product_pic'] = I('post.product_pic') ;//商品图片
                I('post.product_name') && $data2['product_name'] = I('post.product_name') ;//商品名称
                I('post.tk_price') && $data2['tk_price'] = I('post.tk_price') ;//退款金额
                I('post.tkyy') && $data2['tkyy'] = I('post.tkyy') ;//退款原因

                I('post.face180') && $data2['tk_pic'] = I('post.face180');//上传凭证
             // dump($data2);die;
                $data2['userid']=$_SESSION['user_id'];
                $data2['status']=1;//默认为1（未审核）
                $data2['sq_time']=time();//申请时间
                $data2['type']='tk';//申请类别 tk退款申请  th换货申请
                
				
				if ($data2) {
					//添加
					$add = _getAdd($this->reimburse,$data2,$cache);
					$data3['tk_num']=number('T',$add['id']);//退款编号
					//修改
					M($this->reimburse)->where(array('id'=>$add['id']))->save($data3);
					$data4['refund_state']=1;
					
					$reg=M($this->order)->where(array('order_sn'=>$data2['order_sn']))->save($data4);
					unset($data4);
					$data4['status']=4;

					if(I('post.qb')){

						$order=M($this->order)->where(array('id'=>I('post.id')))->find();
						$arr['order_sn']=$order['order_sn'];
        	            $sptable=M($this->order_product)->where($arr)->select();
        	            for($i=0;$i<count($sptable);$i++){
        	            	
					        M($this->order_product)->where(array('id'=>$sptable[$i]['id']))->save($data4);//全部改变订单状态（待退款）

        	            }
					}else{
						M($this->order_product)->where(array('id'=>I('post.id')))->save($data4);//改变订单状态（待退款）
					}

				}

				if ($add) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('提交成功！');location.href='/member/tksq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }


	/*
	*退款申请
	*/	
    public function tuikuan(){

    	$map['id']=I('get.id');
    	$this->tkid=$map['id'];
    	if(I('get.qb')){
    		$qb='qb';
    		$this->qb=$qb;
    		$list2=M($this->order)->where($map)->find();

    	}else{
    		$list=M($this->order_product)->where($map)->find();
    	    $map2['order_id']=$list['order_id'];
    	    $list2=M($this->order)->where($map2)->find();
    	}

    	
    	$this->assign('list',$list);
    	$this->assign('list2',$list2);

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('tkhash',I('post.tkhash'));	
			
			if ($hash){

                if(!I('post.tkyy')){
                	echo "<SCRIPT language=JavaScript>alert('请输入退款原因！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!I('post.face180')){
                	echo "<SCRIPT language=JavaScript>alert('请上传凭证！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                I('post.order_sn') && $data2['order_sn'] = I('post.order_sn') ;//订单号
                I('post.store_name') && $data2['store_name'] = I('post.store_name') ;//商铺名称
                I('post.product_pic') && $data2['product_pic'] = I('post.product_pic') ;//商品图片
                I('post.product_name') && $data2['product_name'] = I('post.product_name') ;//商品名称
                I('post.tk_price') && $data2['tk_price'] = I('post.tk_price') ;//退款金额
                I('post.tkyy') && $data2['tkyy'] = I('post.tkyy') ;//退款原因

                I('post.face180') && $data2['tk_pic'] = I('post.face180');//上传凭证
             // dump($data2);die;
                $data2['userid']=$_SESSION['user_id'];
                $data2['status']=1;//默认为1（未审核）
                $data2['sq_time']=time();//申请时间
                $data2['type']='tk';//申请类别 tk退款申请  th换货申请
                
				
				if ($data2) {
					//添加
					$add = _getAdd($this->reimburse,$data2,$cache);
					$data3['tk_num']=number('T',$add['id']);//退款编号
					//修改
					M($this->reimburse)->where(array('id'=>$add['id']))->save($data3);
					$data4['refund_state']=1;
					
					$reg=M($this->order)->where(array('order_sn'=>$data2['order_sn']))->save($data4);
					unset($data4);
					$data4['status']=4;

					if(I('post.qb')){

						$order=M($this->order)->where(array('id'=>I('post.id')))->find();
						$arr['order_sn']=$order['order_sn'];
        	            $sptable=M($this->order_product)->where($arr)->select();
        	            for($i=0;$i<count($sptable);$i++){
        	            	
					        M($this->order_product)->where(array('id'=>$sptable[$i]['id']))->save($data4);//全部改变订单状态（待退款）

        	            }
					}else{
						M($this->order_product)->where(array('id'=>I('post.id')))->save($data4);//改变订单状态（待退款）
					}

				}

				if ($add) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('提交成功！');location.href='/member/tksq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }

    /*
	* 退款申请列表
	*/	
	public function tksqlb() {	

        $kstime = I('get.add_time_from');
        $jstime = I('get.add_time_to');
        $timeks=strtotime($kstime);
        $timejs=strtotime($jstime);
        if($kstime<>''){
            $this->kstime=I('get.add_time_from');
        }
        if($jstime<>''){
            $this->jstime=I('get.add_time_to');
        }
        if ($kstime <> '' && $jstime <> '') {
            $where['sq_time'] = array(array('egt',$timeks),array('lt',$timejs));
        }elseif ($kstime <> '' && $jstime == '') {
            $where['sq_time'] = array('egt',$timeks);
        }elseif ($kstime == '' && $jstime <> '') {
            $where['sq_time'] = array('lt',$timejs);
        }

        if(I('get.type')){
            $type = I('get.type');
            if($type=='order_sn'){
            	$this->type0 = "selected";
            }elseif($type=='tk_num'){
            	$this->type1 = "selected";
            }elseif($type=='product_name'){
            	$this->type2 = "selected";
            }
        }

        if(I('get.key')){
        	$this->keys = I('get.key');
        	$where[$type]=I('get.key');
        }

		// $cache = 'user_'.$_SESSION['user_id'];
		$where['userid']=$_SESSION['user_id'];
		$where['type']='tk';
		// dump($where);
		$num=3;

		$count = M($this->reimburse)->where($where)->count();// 查询满足要求的总记录数

		$p = getpage($count, $num);

		$list = M($this->reimburse)->where($where)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();

		$this->assign('list',$list);
		$this->assign('page',$p->show());


		$this->display();
	}

	/*
	* 退款申请详情
	*/	
	public function tksqxx() {	

		$map['id']=I('get.id');
    	
    	$list = M($this->reimburse)->where($map)->find();
    	$list2=M($this->order)->where(array('order_sn'=>$list['order_sn']))->find();
    	if($list['product_name']=='订单商品全部退款'){

    		$list2['sptable']=M($this->order_product)->where(array('order_sn'=>$list['order_sn']))->select();
    		
    	}else{
    		$list2['sptable']=M($this->order_product)->where(array('order_sn'=>$list['order_sn'],'product_name'=>$list['product_name']))->select();
    		$list3=M($this->order_product)->where(array('order_sn'=>$list['order_sn'],'product_name'=>$list['product_name']))->find();
    		$list2['order_amount']=$list3['product_price']*$list3['product_num'];

    	}

    	$sjmc=M($this->store)->where(array('store_name'=>$list2['store_name']))->find();

    	
    	$this->assign('list',$list);
    	$this->assign('list2',$list2);
    	$this->assign('sjmc',$sjmc);

		$this->display();
	}


	/*
	*换货申请
	*/	
    public function huanhuo(){

    	$map['id']=I('get.id');
    	$this->tkid=$map['id'];
    	if(I('get.qb')){
    		$qb='qb';
    		$this->qb=$qb;
    		$list2=M($this->order)->where($map)->find();

    	}else{
    		$list=M($this->order_product)->where($map)->find();
    	    $map2['order_id']=$list['order_id'];
    	    $list2=M($this->order)->where($map2)->find();

    	}

    	
    	$this->assign('list',$list);
    	$this->assign('list2',$list2);

    	$cache = 'user_'.$_SESSION['user_id'];		
		if (IS_POST) {
			$str = "id=%d and username='%s'";
			$data = array($_SESSION['user_id'],$_SESSION['user_name']);	
			//hash
			$hash = $this->SuijiHash('tkhash',I('post.tkhash'));	
			
			if ($hash){

                if(!I('post.tkyy')){
                	echo "<SCRIPT language=JavaScript>alert('请输入换货原因！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }
                if(!I('post.face180')){
                	echo "<SCRIPT language=JavaScript>alert('请上传凭证！');javascript:history.go(-1);</SCRIPT>";
                	die();
                }

                I('post.order_sn') && $data2['order_sn'] = I('post.order_sn') ;//订单号
                I('post.store_name') && $data2['store_name'] = I('post.store_name') ;//商铺名称
                I('post.product_pic') && $data2['product_pic'] = I('post.product_pic') ;//商品图片
                I('post.product_name') && $data2['product_name'] = I('post.product_name') ;//商品名称
                I('post.product_price') && $data2['product_price'] = I('post.product_price') ;//商品单价
                I('post.product_num') && $data2['product_num'] = I('post.product_num') ;//商品数量
                I('post.tk_price') && $data2['tk_price'] = I('post.tk_price') ;//退款金额
                I('post.tkyy') && $data2['tkyy'] = I('post.tkyy') ;//退款原因

                I('post.face180') && $data2['tk_pic'] = I('post.face180');//上传凭证
             // dump($data2);die;
                $data2['userid']=$_SESSION['user_id'];
                $data2['status']=1;//默认为1（未审核）
                $data2['sq_time']=time();//申请时间
                $data2['type']='th';//申请类别 tk退款申请  th换货申请
                
				
				if ($data2) {
					//添加
					$add = _getAdd($this->reimburse,$data2,$cache);
					$data3['tk_num']=number('H',$add['id']);//换货编号
					//修改
					M($this->reimburse)->where(array('id'=>$add['id']))->save($data3);

					// $data4['status']=4;
					
					// if(I('post.qb')){
					// 	$order=M($this->order)->where(array('id'=>I('post.id')))->find();
					// 	$arr['order_sn']=$order['order_sn'];
     //    	            $sptable=M($this->order_product)->where($arr)->select();
     //    	            for($i=0;$i<count($sptable);$i++){
        	            	
					//         M($this->order_product)->where(array('id'=>$sptable[$i]['id']))->save($data4);//全部改变订单状态（待退款）

     //    	            }
					// }else{
					// 	M($this->order_product)->where(array('id'=>I('post.id')))->save($data4);//改变订单状态（待退款）
					// }

				}

				if ($add) {
					unset($data2);
					//dump($data2);die;					
					echo "<SCRIPT language=JavaScript>alert('提交成功！');location.href='/member/thsq.html'</SCRIPT>";
				} else {
					echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
				}
			} else {
				echo "<SCRIPT language=JavaScript>alert('提交失败！');javascript:history.go(-1);</SCRIPT>";
			}
			
		}		
		
	    $this->display(); 
    }


    /*
	* 换货申请列表
	*/	
	public function thsqlb() {	

        $kstime = I('get.add_time_from');
        $jstime = I('get.add_time_to');
        $timeks=strtotime($kstime);
        $timejs=strtotime($jstime);
        if($kstime<>''){
            $this->kstime=I('get.add_time_from');
        }
        if($jstime<>''){
            $this->jstime=I('get.add_time_to');
        }
        if ($kstime <> '' && $jstime <> '') {
            $where['sq_time'] = array(array('egt',$timeks),array('lt',$timejs));
        }elseif ($kstime <> '' && $jstime == '') {
            $where['sq_time'] = array('egt',$timeks);
        }elseif ($kstime == '' && $jstime <> '') {
            $where['sq_time'] = array('lt',$timejs);
        }

        if(I('get.type')){
            $type = I('get.type');
            if($type=='order_sn'){
            	$this->type0 = "selected";
            }elseif($type=='tk_num'){
            	$this->type1 = "selected";
            }elseif($type=='product_name'){
            	$this->type2 = "selected";
            }
        }

        if(I('get.key')){
        	$this->key = I('get.key');
        	$where[$type]=I('get.key');
        }

		// $cache = 'user_'.$_SESSION['user_id'];
		$where['userid']=$_SESSION['user_id'];
		$where['type']='th';
		// dump($where);
		$num=3;

		$count = M($this->reimburse)->where($where)->count();// 查询满足要求的总记录数

		$p = getpage($count, $num);

		$list = M($this->reimburse)->where($where)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();

		$this->assign('list',$list);
		$this->assign('page',$p->show());


		$this->display();
	}

	/*
	* 换货申请详情
	*/	
	public function thsqxx() {	

		$map['id']=I('get.id');
    	
    	$list = M($this->reimburse)->where($map)->find();
    	$list2=M($this->order)->where(array('order_sn'=>$list['order_sn']))->find();
    	if($list['product_name']=='订单商品全部退款'){

    		$list2['sptable']=M($this->order_product)->where(array('order_sn'=>$list['order_sn']))->select();
    		
    	}else{
    		$list2['sptable']=M($this->order_product)->where(array('order_sn'=>$list['order_sn'],'product_name'=>$list['product_name']))->select();
    		$list3=M($this->order_product)->where(array('order_sn'=>$list['order_sn'],'product_name'=>$list['product_name']))->find();
    		$list2['order_amount']=$list3['product_price']*$list3['product_num'];

    	}

    	$sjmc=M($this->store)->where(array('store_name'=>$list2['store_name']))->find();

    	
    	$this->assign('list',$list);
    	$this->assign('list2',$list2);
    	$this->assign('sjmc',$sjmc);

		$this->display();
	}



	/*
	* 收藏商品
	*/	
	public function wdsc_sp() {	

		$map['userid']=$_SESSION['user_id'];
		$map['sc_lx']='sp';
    	
    	$zscid = M($this->collect)->field("sc_id")->where($map)->order('id DESC')->select();

		$ff=array();
		for($i=0;$i<count($zscid);$i++)
        {
        	$ff[]= array('like',$zscid[$i]['sc_id']);
        }
        $a=count($ff);
        if($a>=1){
        	$ff[$a]='ThinkPHP';
            $ff[$a+1]='or';

            $data['id']=$ff;
        }else{
        	$data['id']='';
        }
// dump($ff);

		$num=8;

		$count = M($this->product)->where($data)->count();// 查询满足要求的总记录数

		$p = getpage($count, $num);

		$list = M($this->product)->where($data)->limit($p->firstRow, $p->listRows)->select();
		for($i=0;$i<count($list);$i++)
        {
        	$dp = M($this->store)->where(array('store_id'=>$list[$i]['st_id']))->find();
        	$list[$i]['dpname']=$dp['store_name'];//店铺名称
        	// dump($dp);
        	$list[$i]['scrq'] = 0;
        	$list[$i]['z_xs'] = 0;
        	$list[$i]['z_pl'] = 0;
        	$list[$i]['scrq'] += M($this->collect)->where(array('sc_id'=>$list[$i]['id']))->count();//总收藏人气
        	$list[$i]['z_xs'] += M($this->order_product)->where(array('product_id'=>$list[$i]['id']))->sum('product_num');//总出售数量
        	// $list[$i]['z_pl'] += M($this->comment)->where(array('product_id'=>$list[$i]['id']))->count();//总评论数
        	$map['sc_id']=$list[$i]['id'];
        	$scid = M($this->collect)->where($map)->find();
        	$list[$i]['sc_id'] = $scid['id'];//收藏记录id

        }

    	
    	$this->assign('list',$list);
    	$this->assign('page',$p->show());

		$this->display();
	}


	/*
	*删除收藏记录
	*/	
    public function del_sc(){
    	$id=$_GET;
    	unset($id['/member/delsc_html']);
    	$count=count($id);
        if($count>=1){
    	    // dump($id);
    	    $num=0;
    	    foreach($id as $k => $v)
            {
        	    // echo $v.'<br>';
        	    M($this->collect)->where(array('id'=>$v))->delete();
        	    $num+=1;
            }
            // echo count($id).'<br>';
            // echo $num;
            // die;

    	    if ($num==$count) {
								
			    echo "<SCRIPT language=JavaScript>alert('删除成功！');self.location=document.referrer;</SCRIPT>";
		    } else {
			    echo "<SCRIPT language=JavaScript>alert('删除失败！');javascript:history.go(-1);</SCRIPT>";
		    }
	    }else{
	    	echo "<SCRIPT language=JavaScript>alert('没有选中要删除的收藏！');javascript:history.go(-1);</SCRIPT>";

	    }

 
    }


	/*
	* 收藏店铺
	*/	
	public function wdsc_dp() {	

		$map['userid']=$_SESSION['user_id'];
		$map['sc_lx']='dp';
    	
    	$zscid = M($this->collect)->field("sc_id")->where($map)->order('id DESC')->select();

		$ff=array();
		for($i=0;$i<count($zscid);$i++)
        {
        	$ff[]= array('like',$zscid[$i]['sc_id']);
        }
        $a=count($ff);
        if($a>=1){
        	$ff[$a]='ThinkPHP';
            $ff[$a+1]='or';

            $data['store_id']=$ff;
        }else{
        	$data['store_id']='';
        }
// dump($ff);

		$num=8;

		$count = M($this->store)->where($data)->count();// 查询满足要求的总记录数

		$p = getpage($count, $num);

		$list = M($this->store)->where($data)->limit($p->firstRow, $p->listRows)->select();
		for($i=0;$i<count($list);$i++)
        {
        	// $dp = M($this->store)->where(array('id'=>$list[$i]['store_id']))->find();
        	// $list[$i]['dpname']=$dp['store_name'];//店铺名称
        	// $list[$i]['scrq'] = 0;
        	// $list[$i]['z_xs'] = 0;
        	// $list[$i]['z_pl'] = 0;
        	// $list[$i]['scrq'] += M($this->collect)->where(array('sc_id'=>$list[$i]['id']))->count();//总收藏人气
        	// $list[$i]['z_xs'] += M($this->order_product)->where(array('product_id'=>$list[$i]['id']))->sum('product_num');//总出售数量
        	// // $list[$i]['z_pl'] += M($this->comment)->where(array('product_id'=>$list[$i]['id']))->count();//总评论数
        	$map['sc_id']=$list[$i]['store_id'];
        	$scid = M($this->collect)->where($map)->find();
        	$list[$i]['sc_id'] = $scid['id'];//收藏记录id

        }

    	
    	$this->assign('list',$list);
    	$this->assign('page',$p->show());

		$this->display();
	}

	/*
	* 我要评价
	*/	
	public function wy_pj() {	

        if($_POST){
		    $data['pj_level']=I('post.pj_level');
		    $data['pj_content']=I('post.pj_content');
		    $str=I('post.pj_content');
		    if($data['pj_level']==0){
			    echo "<SCRIPT language=JavaScript>alert('请给商品评分！');javascript:history.go(-1);</SCRIPT>";
                die();
		    }
		    if(!I('post.pj_content')){
			    echo "<SCRIPT language=JavaScript>alert('请输入评价详情！');javascript:history.go(-1);</SCRIPT>";
                die();
		    }
		    if(strlen($str) > 250){
		    // if(!isset($str{250})){
			    echo "<SCRIPT language=JavaScript>alert('评价信息最多填写250字！');javascript:history.go(-1);</SCRIPT>";
                die();
		    }
		    if(I('post.anony')){
			    $data['nmpj']=I('post.anony');
		    }
		    $data['status']=5;//改变订单状态 完成订单
		    $data['pj_userid']=$_SESSION['user_id'];
		    $data['pjtime']=time();

		    $reg=M($this->order_product)->data($data)->where(array('id'=>I('post.pjid')))->save();

		    if ($reg) {
								
			    echo "<SCRIPT language=JavaScript>alert('评价成功！');location.href='/member/jypj.html'</SCRIPT>";
		    } else {
			    echo "<SCRIPT language=JavaScript>alert('评价失败！');javascript:history.go(-1);</SCRIPT>";
		    }

	    }else{

	    	$map['id']=I('get.id');
    	    $this->pjid=$map['id'];
    	
            $list=M($this->order_product)->where($map)->find();

    	    $this->assign('list',$list);

    	    $this->display();
	    }
		
	}


	/*
	* 交易评价列表
	*/	
	public function jypjlb() {	

	    $map['pj_userid']=$_SESSION['user_id'];
    	$this->pjid=$map['id'];
    	$num=3;

		$count = M($this->order_product)->where($map)->count();// 查询满足要求的总记录数

		$p = getpage($count, $num);

		$list = M($this->order_product)->where($map)->limit($p->firstRow, $p->listRows)->select();
    	

    	$this->assign('list',$list);
    	$this->assign('page',$p->show());

    	$this->display();
	}


	/*
	* 我要晒单
	*/	
	public function pjsd() {	

		if($_POST){
		    $data['sd_pic1']=I('post.sd_pic1');
		    $data['sd_pic2']=I('post.sd_pic2');
		    $data['sd_pic3']=I('post.sd_pic3');
		    $data['sd_pic4']=I('post.sd_pic4');
		    $data['sd_pic5']=I('post.sd_pic5');
		    
		    $reg=M($this->order_product)->data($data)->where(array('id'=>I('post.pjid')))->save();

		    if ($reg) {
								
			    echo "<SCRIPT language=JavaScript>alert('晒单成功！');location.href='/member/jypj.html'</SCRIPT>";
		    } else {
			    echo "<SCRIPT language=JavaScript>alert('晒单失败！');javascript:history.go(-1);</SCRIPT>";
		    }

	    }else{

	    	$map['id']=I('get.id');
    	    $this->pjid=$map['id'];
  
		   $list = M($this->order_product)->where($map)->find();
    	

    	   $this->assign('list',$list);
    	

    	   $this->display();
	    }
  
	}

	








	
}